package com.cgq.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cgq.pojo.Stock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * *  Author:陈国强
 * *  Description:
 * *  Date:2023/2/15 14:34
 */
@Repository
public interface StockMapper extends BaseMapper<Stock> {

    //利用sql语句进行更新操作
    @Update("update db_stock set count = count - #{count} where product_code = #{product_code} and count >= #{count}")
    int updateStock(@Param("product_code") String product_code,@Param("count") Integer count);

    //利用悲观锁进行演示商品减库存操作
    @Select("select * from db_stock where product_code = #{productCode} for update")
    List<Stock> queryStock(@Param("productCode") String productCode);
}
